<h1 class="page-header">
    <small>订单列表</small>
</h1>
<hr/>
<div class="panel panel-inverse" data-sortable-id="form-stuff-5">
    <div class="panel-heading">
        <h4 class="panel-title">订单查询</h4>
    </div>
    <div class="panel-body">
        <form id="orderForm" name="orderForm" method="post" class="form-inline">
            <div class="form-group m-r-10">
                <input type="text" class="form-control" name="EQ_userId" value="${EQ_userId}" placeholder="会员ID">
            </div>
            <#if storeId < 1>
            <div class="form-group m-r-10">
                <input type="text" class="form-control" name="EQ_storeId" value="${EQ_storeId}" placeholder="店铺ID">
            </div>
            </#if>
            <div class="form-group m-r-10">
                <input type="text" class="form-control" name="EQ_mobile" value="${EQ_mobile}" placeholder="会员手机号">
            </div>
            <div class="form-group m-r-10">
                <input type="text" class="form-control" name="EQ_orderSn" value="${EQ_orderSn}" placeholder="订单号">
            </div>
            <div class="form-group m-r-10">
                <select class="form-control" name="EQ_type" id="EQ_type">
                    <option value="">订单类型</option>
                    <#if typeList?has_content && typeList?exists>
                    <#list typeList as pf>
                    <option value="${pf.key}" <#if params.EQ_type== pf.key> selected</#if>>${pf.value}</option>
                    </#list>
                    </#if>
                </select>
            </div>
            <div class="form-group m-r-10">
                <select class="form-control" name="EQ_payStatus" id="EQ_payStatus">
                    <option value="">支付状态</option>
                    <#if payStatusList?has_content && payStatusList?exists>
                    <#list payStatusList as pf>
                    <option value="${pf.key}" <#if params.EQ_payStatus== pf.key> selected</#if>>${pf.value}</option>
                    </#list>
                    </#if>
                </select>
            </div>
            <div class="form-group m-r-10">
                <select class="form-control" name="EQ_status" id="EQ_status">
                    <option value="">订单状态</option>
                    <#if statusList?has_content && statusList?exists>
                    <#list statusList as pf>
                    <option value="${pf.key}" <#if params.EQ_status== pf.key> selected</#if>>${pf.value}</option>
                    </#list>
                    </#if>
                </select>
            </div>
            <button type="button" class="btn btn-sm btn-success" onclick="postDataByForm('backend/order/list','displayArea','orderForm')"><i class="fa fa-search"></i>查询</button>
        </form>
    </div>
</div>
<hr/>
<div class="panel panel-inverse" data-sortable-id="table-basic-4">
    <div class="panel-heading">
        <h4 class="panel-title">订单列表</h4>
    </div>
    <div class="panel-body">
        <table class="table table-striped table-bordered">
            <thead>
            <tr>
                <th>订单号</th>
                <th>会员ID</th>
                <th>会员名称</th>
                <th>类型</th>
                <#if storeId < 1>
                <th>所属店铺</th>
                </#if>
                <th>总金额</th>
                <th>支付金额</th>
                <th>优惠金额</th>
                <th>积分金额</th>
                <th>创建时间</th>
                <th>支付状态</th>
                <th>订单状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <#if paginationResponse?has_content && paginationResponse.content?exists && paginationResponse.content?size gt 0>
                <#list paginationResponse.content as ct>
                    <tr>
                        <td>${ct.orderSn}</td>
                        <td>${ct.userId}</td>
                        <td>${ct.userInfo.name}</td>
                        <td>${ct.typeName}</td>
                        <#if storeId < 1>
                        <td><#if ct.storeInfo>${ct.storeInfo.name}<#else>--</#if></td>
                        </#if>
                        <td>${ct.amount}</td>
                        <td><#if ct.payAmount gt 0>${ct.payAmount}<#else>0.00</#if></td>
                        <td><#if ct.discount gt 0>${ct.discount}<#else>0.00</#if></td>
                        <td><#if ct.pointAmount gt 0>${ct.pointAmount}<#else>0.00</#if></td>
                        <td>${ct.createTime}</td>
                        <td>
                            <#if ct.payStatus='B'>
                            <span class="status-active">已支付</span>
                            <#else>
                            <span class="status-disabled">未支付</span>
                            </#if>
                        </td>
                        <td>
                             <span class="status-normal">${ct.statusText}</span>
                        </td>
                        <td>
                            <a class="label label-success small-btn" href="javascript:getData('${rc.contextPath}/backend/order/detail/${ct.id}', 'displayArea');" title="详情"><i class="fa fa-eye"></i>详情</a>
                            <#if ct.type=='goods'>
                               <#if ct.status=='B'><a class="label label-danger small-btn" href="javascript:doDelivered(${ct.id});" title="发货"><i class="fa fa-eye"></i>发货</a></#if>
                            </#if>
                        </td>
                    </tr>
                </#list>
            <#else>
            <tr class="gradeA even" role="row">
                <td colspan="12" class="text-center">没有符合条件的数据！</td>
            </tr>
            </#if>
        </table>
    </div>
</div>
<@sp.pagination recordBean=paginationResponse action="${rc.contextPath}/backend/order/list" formName="orderForm"/>
<script type="application/javascript">
    /**
     * 确定发货
     * @param orderId
     */
    function doDelivered(orderId) {
        var html = '<div style="margin-bottom:10px;"><span><i style="color:red;margin-right:5px;">*</i>物流公司：</span><input type="text" id="expressCompany" placeholder="请填写物流公司名称" name="expressCompany" value=""/></div>'+
                   '<div><span><i style="color:red;margin-right:5px;">*</i>快递单号：</span><input id="expressNo" type="text" name="expressNo" placeholder="请填写快递单号" value=""/></div>';
        layer.confirm(html, {
            btn: ['确定', '取消'], title: '填写物流信息'
        }, function () {
            var expressCompany = $("#expressCompany").val();
            var expressNo = $("#expressNo").val();

            if (expressCompany.length < 1 || expressNo.length < 1) {
                layer.alert("物流单号和物流公司不能为空！");
                return;
            }

            $.ajax({
                type: "POST",
                data: {"expressCompany": expressCompany, "expressNo": expressNo, "orderId": orderId},
                url: "${rc.contextPath}/backend/order/delivered",
                success: function (data) {
                    if (data.result) {
                        layer.alert('发货成功！');
                        return;
                    } else {
                        layer.alert('抱歉，发货失败！');
                        return;
                    }
                }
            })

        }, function () {
            $.close();
        });
    }
</script>